package com.learning.algorithm.sort;

import com.learning.algorithm.sort.divideAndConquer.MergeSort;
import com.learning.algorithm.sort.divideAndConquer.QuickSort;
import com.learning.algorithm.sort.simpleSort.BubblingSort;
import com.learning.algorithm.sort.simpleSort.InsertSort;
import com.learning.algorithm.sort.simpleSort.Insert_ShellSort;
import com.learning.algorithm.sort.simpleSort.SelectSort;

/**
 * @Author: lishi
 * @Description: ${description}
 * @Date: 2021/11/23 16:03
 */
public class IntSortMain {
    public static void main(String[] args) {
        int length = 10000;
        int[] originArray = ArraysUtil.genNoDuplicateIntArray(length);
        int[] selectSortArray = new int[length];
        int[] bubblingSortArray = new int[length];
        int[] insertSortArray = new int[length];
        int[] mergeSortArray = new int[length];
        int[] shellArray = new int[length];
        int[] quickArray = new int[length];

        System.arraycopy(originArray, 0, selectSortArray, 0, length);
        System.arraycopy(originArray, 0, bubblingSortArray, 0, length);
        System.arraycopy(originArray, 0, insertSortArray, 0, length);
        System.arraycopy(originArray, 0, mergeSortArray, 0, length);
        System.arraycopy(originArray, 0, shellArray, 0, length);
        System.arraycopy(originArray, 0, quickArray, 0, length);

        checkSort(originArray,selectSortArray,new SelectSort());
        checkSort(originArray,bubblingSortArray,new BubblingSort());
        checkSort(originArray,insertSortArray,new InsertSort());
        checkSort(originArray,mergeSortArray,new MergeSort());
        checkSort(originArray,shellArray,new Insert_ShellSort());
        checkSort(originArray,quickArray,new QuickSort());
    }

    private static void checkSort(int[] originArray, int[] sortArray, IntArraySort intArraySort) {
        long startTime = System.currentTimeMillis();
        sortArray = intArraySort.sort(sortArray);
        System.out.println(sortArray.length + "size Array! " + intArraySort.getDesc() + " cost : " + (System.currentTimeMillis() - startTime) + "ms!result:" + CheckSort.checkSortResult(originArray, sortArray));
    }
}
